import torch
import torch.nn as nn

class TextCNN(nn.Module):
    def __init__(self, vocab_size, embed_dim, num_classes):
        super(TextCNN, self).__init__()
        self.embedding = nn.Embedding(vocab_size, embed_dim)
        self.conv = nn.Conv2d(1, 100, (3, embed_dim))
        self.dropout = nn.Dropout(0.5)
        self.fc = nn.Linear(100, num_classes)

    def forward(self, x):
        x = self.embedding(x).unsqueeze(1)
        x = self.conv(x).squeeze(3)
        x = torch.relu(x)
        x = torch.max(x, dim=2)[0]
        x = self.dropout(x)
        x = self.fc(x)
        return x
